﻿<UserControl
    x:Class="NewsReaderApp.Views.LandscapeView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:NewsReaderApp.Views"
    xmlns:converters="using:NewsReaderApp.Helpers"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400">
    <Grid x:Name="landscape" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="45" />
            <RowDefinition Height="45" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="222"/>
            <ColumnDefinition Width="222"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Grid.ColumnSpan="3" MaxWidth="1120">
            <Border HorizontalAlignment="Left" BorderThickness="0"
                                Visibility="{Binding Path=SelectedFeed.SelectedItem.ImageUriExists, Converter={StaticResource boolToVis}}">
                <Image Source="{Binding SelectedFeed.SelectedItem.ImageUri}" Stretch="Uniform" Margin="1" MaxWidth="100"/>
            </Border>
            <TextBlock
                       Style="{StaticResource BasicTextStyle}"
                       TextWrapping="NoWrap"
                       Text="{Binding Path=SelectedFeed.SelectedItem.Title}" 
                       FontSize="30" 
                       Margin="2" 
                       HorizontalAlignment="Left" 
                       VerticalAlignment="Center"/>
        </StackPanel>
        <StackPanel Orientation="Horizontal" Grid.Row="1"  Grid.ColumnSpan="3" >
            <TextBlock FontSize="30" Margin="2" HorizontalAlignment="Left" 
                       VerticalAlignment="Center" Style="{StaticResource BasicTextStyle}">
                <Run>
                    <Run.Text>
                        <Binding Path="SelectedFeed.SelectedItem.PublishedTime" Converter="{StaticResource dateFormatter}" 
                                 ConverterParameter="dddd, MMMM dd, yyyy hh:mm tt"/>
                    </Run.Text>
                </Run>
            </TextBlock>
        </StackPanel>
        <TextBlock Text="{StaticResource AppName}" Grid.Row="0" Grid.ColumnSpan="3" HorizontalAlignment="Right" 
                       Style="{StaticResource BasicTextStyle}"
                       Margin="3" 
                       VerticalAlignment="Center"
                       FontSize="25"/>
        <ListView Grid.Row="2"
                        IsTabStop="False" TabNavigation="Once"
                        ItemTemplate="{StaticResource FeedInfoTemplate}" SelectedItem="{Binding SelectedFeed, Mode=TwoWay}"
                        ItemsSource="{Binding Feeds, Mode=TwoWay}">
        </ListView>
        <ListView Grid.Row="2" Grid.Column="1" 
                        ItemsSource="{Binding SelectedFeed.FeedItems}" 
                        SelectedItem="{Binding SelectedFeed.SelectedItem, Mode=TwoWay}"
                        ItemTemplate="{StaticResource FeedItemTemplate}">
        </ListView>
        <Border Style="{StaticResource ContentBorder}"  Grid.Column="2"  Grid.Row="2" 
                         Margin="2,0,2,0">
            <Border.Resources>
                <converters:NewsTextToXamlConverter x:Key="newsToXaml"/>
            </Border.Resources>

            <local:CustomFlipView ItemsSource="{Binding SelectedFeed.FeedItems}" x:Name="contentViewHolder"  
                          SelectedItem="{Binding SelectedFeed.SelectedItem, Mode=TwoWay}">
                <FlipView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </FlipView.ItemsPanel>
                <FlipView.ItemTemplate>
                    <DataTemplate>
                        <ScrollViewer Style="{StaticResource VerticalScrollViewerStyle}" 
                                  HorizontalScrollBarVisibility="Disabled" 
                                  VerticalScrollBarVisibility="Auto"
                                  FlowDirection="{Binding Path=Content.FlowDirection, RelativeSource={RelativeSource Self}}"
                                  x:Name="contentView">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <Image Source="{Binding ImageUri}" Stretch="Uniform" Margin="1" MaxHeight="150" HorizontalAlignment="Left"
                                       Visibility="{Binding ImageUri, Converter={StaticResource nullToVis}}"/>
                                <Grid  Grid.Row="1" DataContext="{Binding Path=FullText, Converter={StaticResource newsToXaml}}">
                                    <ContentPresenter Content="{Binding}"/>
                                    <StackPanel Orientation="Vertical"  Opacity=".7" 
                                                 Visibility="{Binding Converter={StaticResource negNullToVis}}"
                                                HorizontalAlignment="Center" VerticalAlignment="Center">
                                        <ProgressRing Foreground="{StaticResource ApplicationForegroundThemeBrush}" Height="60" Width="60"
                                               IsActive="True" 
                                               Margin="5" />
                                        <TextBlock Foreground="{StaticResource ApplicationForegroundThemeBrush}"
                                                   Text="Loading..." HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </StackPanel>
                                </Grid>
                            </Grid>
                        </ScrollViewer>
                    </DataTemplate>
                </FlipView.ItemTemplate>
            </local:CustomFlipView>
        </Border>
    </Grid>
</UserControl>
